from dao.statistics_dao import (get_department_call_by_z_t_dao,
                                get_major_call_by_z_t_dao,
                                get_grade_call_by_z_t_dao)
from dao.department_dao import (get_department_by_f_id_dao)
from dao.major_dao import (get_major_by_m_id)
from dao.grade_dao import (get_grade_by_class_id)



def get_department_call_by_z_t(z, t):
    res = get_department_call_by_z_t_dao(z, t)
    index = 0
    for r in res:
        department = get_department_by_f_id_dao(r["department_id"])[0]
        r["id"] = index + 1
        r["department_name"] = department["f_name"]
        r["department_no_at_number"] = r["department_all_number"] - r["department_at_number"]
        index += 1
    return res


def get_major_call_by_z_t(z, t, d_id):
    res = get_major_call_by_z_t_dao(z, t, d_id)
    index = 0
    for r in res:
        major = get_major_by_m_id(r["major_id"])
        r["id"] = index + 1
        r["major_name"] = major["m_name"]
        r["major_no_at_number"] = r["major_all_number"] - r["major_at_number"]
        index += 1
    return res


def get_grade_call_by_z_t(z, t, m_id):
    res = get_grade_call_by_z_t_dao(z, t, m_id)
    index = 0
    for r in res:
        grade = get_grade_by_class_id(r["class_id"])
        r["id"] = index + 1
        r["grade_name"] = grade["c_name"]
        r["g_rate"] = str(format((100 * r["grade_at_number"]) / r["grade_all_number"],
                   ".2f")) + "%"
        index += 1
    return res